package cn.itcast.jk.service.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.itcast.jk.dao.FactoryDao;
import cn.itcast.jk.domain.Factory;
import cn.itcast.jk.pagination.Page;
import cn.itcast.jk.service.FactoryService;

@Service
public class FactoryServiceImpl implements FactoryService{
	@Autowired
	FactoryDao factoryDao;

	@Override
	public List<Factory> findPage(Page page) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Factory> find(Map paraMap) {
		// TODO Auto-generated method stub
		return factoryDao.find(paraMap);
	}

	@Override
	public Factory get(Serializable id) {
		// TODO Auto-generated method stub
		return factoryDao.get(id);
	}

	@Override
	public void insert(Factory factory) {
		// TODO Auto-generated method stub
		factory.setId(UUID.randomUUID().toString());	//设置UUID
		factory.setState("1");              			// 是否启用:1启用，0停用
		factoryDao.insert(factory);
	}

	@Override
	public void update(Factory factory) {
		// TODO Auto-generated method stub
		factoryDao.update(factory);
	}

	@Override
	public void deleteById(Serializable id) {
		// TODO Auto-generated method stub
		factoryDao.deleteById(id);
	}

	@Override
	public void delete(Serializable[] ids) {
		// TODO Auto-generated method stub
		factoryDao.delete(ids);
	}

	@Override
	public void start(Serializable[] ids) {		//启用
		// TODO Auto-generated method stub
		Map map = new HashMap<>();
		map.put("ids", ids);
		map.put("state", 1);
		factoryDao.updateState(map);
	}

	@Override
	public void stop(Serializable[] ids) {		//停用
		// TODO Auto-generated method stub
		Map map = new HashMap<>();
		map.put("ids", ids);
		map.put("state", 0);
		factoryDao.updateState(map);
	}

	@Override
	public List<Factory> getListFactory() {
		Map map = new HashMap();
		map.put("state","1");			//0：停用，1：启用
		return factoryDao.find(map);	//返回启用状态的生产厂家
	}
}
